<!--_meta 作为公共模版分离出去-->
{{template "../public/header.html"}}
    <!--/meta 作为公共模版分离出去-->

    <title>角色分配</title>
    <meta name="keywords" content="角色分配">
    <meta name="description" content="角色分配">
</head>
<body style="background-color:#fff">
<div class="wap-container">
    <div class="panel">
        <div class="panel-body">
            <form action="" method="post" class="form form-horizontal" id="form-admin-role-add">

                {{/*<div class="row clearfix">
                    <label class="form-label col-xs-4 col-sm-3">网站角色：</label>
                    <div class="form-controls col-xs-8 col-sm-9">
                        <dl class="Hui-admin-permission-list">
                            <input type="hidden" name="role_id" value="{{.roleId}}">
                            <dd>
                                {{range $key,$value := .allNode}}
                                <dl class="clearfix Hui-admin-permission-list2">
                                    <dt>
                                        <label class="">
                                            <input type="checkbox" {{if eq $value.Checked true}}checked{{end}} value="{{$value.Id}}" name="node_ids" id="user-Character-0-0">
                                            {{$value.Name}}</label>
                                    </dt>
                                    {{range $key1,$value1 := $value.NodeItem}}
                                    <dd>
                                        <label class="">
                                            <input type="checkbox" {{if eq $value1.Checked true}}checked{{end}} value="{{$value1.Id}}" name="node_ids" id="user-Character-0-0-0">
                                            {{$value1.Name}}</label>
                                    </dd>
                                    {{end}}
                                </dl>
                                {{end}}
                            </dd>
                        </dl>

                    </div>
                </div>*/}}


                <div class="row clearfix">
                    <label class="form-label col-xs-4 col-sm-3">网站角色：</label>
                    <div class="form-controls col-xs-8 col-sm-9">
                        <input type="hidden" name="role_id" value="{{.roleId}}">
                        {{range $key,$value := .allNode}}
                        <dl class="Hui-admin-permission-list">
                            <dt>
                                <label><input type="checkbox" {{if eq $value.Checked true}}checked{{end}} value="{{$value.Id}}" name="node_ids" id="user-Character-0">{{$value.Name}}</label>
                            </dt>

                            {{range $key1,$value1 := $value.NodeItem}}
                            <dd>
                                <dl class="clearfix Hui-admin-permission-list2">
                                    <dt>
                                        <label class=""><input type="checkbox" {{if eq $value1.Checked true}}checked{{end}} value="{{$value1.Id}}" name="node_ids" id="user-Character-0-0">{{$value1.Name}}</label>
                                    </dt>
                                </dl>
                            </dd>
                            {{end}}

                        </dl>
                        {{end}}
                    </div>
                </div>

                <div class="row clearfix">
                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                        <button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
{{template "../public/footer.html"}}
<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/static/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/static/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function(){
        $(".Hui-admin-permission-list dt input:checkbox").click(function(){
            $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
        });
        $(".Hui-admin-permission-list2 dd input:checkbox").click(function(){
            var l =$(this).parent().parent().find("input:checked").length;
            var l2=$(this).parents(".Hui-admin-permission-list").find(".Hui-admin-permission-list2 dd").find("input:checked").length;
            if($(this).prop("checked")){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
                $(this).parents(".Hui-admin-permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
            }
            else{
                if(l==0){
                    $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
                }
                if(l2==0){
                    $(this).parents(".Hui-admin-permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
                }
            }
        });

        $("#form-admin-role-add").validate({
            rules:{
                roleName:{
                    required:true,
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "/{{config "String" "adminPath" ""}}/role/dorole" ,
                    success: function(data){
                        console.log(data);
                        if(data.code === 200){
                            layer.msg(data.msg,{icon:1,time:1500},function(){
                                parent.window.location.href="/{{config "String" "adminPath" ""}}/role/index";
                                var index=parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:1000});
                        }
                    },
                    error:function(){

                    }
                });
                /*var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);*/
            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
